package com.base.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;

/**
 * 开发公司：个人
 * 版权：个人
 * <p>
 * IndexController
 *
 * @author 刘志强
 * @created Create Time: 2019/5/23
 */
@Controller
public class IndexController {

    // 重定向至首页
    @GetMapping("/")
    public void root(HttpServletResponse httpServletResponse) throws IOException {
        httpServletResponse.sendRedirect("/index");
    }

    @GetMapping("/index")
    public ModelAndView index(ModelMap modelMap) {
        modelMap.put("userName","刘志强");
        modelMap.put("url","https://www.baidu.com/img/bd_logo1.png");
        modelMap.put("date",new Date());
        Map<String,Object> map = new HashMap<>();
        map.put("userName","刘志强");
        map.put("age","12");
        modelMap.put("map",map);
        List<Map> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Map<String,Object> objectMap = new HashMap<>();
            objectMap.put("userName","刘志强" + i);
            objectMap.put("age", i);
            list.add(objectMap);
        }
        modelMap.put("list",list);
        return new ModelAndView("/index", modelMap);
    }
}